package com.acane.instagram.controller;

import com.acane.instagram.pojo.Post;
import com.acane.instagram.pojo.Result;
import com.acane.instagram.service.PostService;
import com.acane.instagram.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/review")
public class ReviewController {

    @Autowired
    private PostService postService;

    @Autowired
    private ReviewService reviewService;

    @PostMapping("/pass/{postId}")
    public Result passAction(@PathVariable String postId) {
        return postService.passAction(postId);
    }

    @PostMapping("/fail/{postId}")
    public Result failAction(@PathVariable String postId, @RequestParam String reason) {
        return postService.failAction(postId, reason);
    }

    @GetMapping("/search/list")
    public Result searchPosts(
            @RequestParam(required = false) String userName,
            @RequestParam(required = false) String content,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size
    ) {
        List<Post> posts = reviewService.searchPosts(userName, content, status, startTime, endTime, page, size);
        System.out.println("===============================================控制器收到的status:" + status);
        return Result.success(posts, posts.size());
    }
}
